package algorithm.leetcode.I1to100;

public class Q14 {

    public String longestCommonPrefix(String[] strs) {
        if (strs.length == 0) return "";

        StringBuilder sb = new StringBuilder();
        int index = 0;

        while (index < strs[0].length()) {
            char c = strs[0].charAt(index);
            for (int i = 1; i < strs.length; i++) {
                if (strs[i].length() <= index || strs[i].charAt(index) != c) return sb.toString();
            }
            sb.append(c);
            index++;
        }
        return sb.toString();
    }
}
